//package com.ptu.spzx.user.service.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.ptu.spzx.common.exception.ptuException;
//import com.ptu.spzx.model.dto.h5.UserLoginDto;
//import com.ptu.spzx.model.dto.h5.UserRegisterDto;
//import com.ptu.spzx.model.dto.system.AssginStuDeptDto;
//import com.ptu.spzx.model.entity.system.SysDept;
//import com.ptu.spzx.model.entity.system.SysUser;
//import com.ptu.spzx.model.entity.user.UserInfo;
//import com.ptu.spzx.model.vo.common.Result;
//import com.ptu.spzx.model.vo.common.ResultCodeEnum;
//import com.ptu.spzx.model.vo.h5.UserInfoVo;
//import com.ptu.spzx.user.mapper.SysDeptMapper;
//import com.ptu.spzx.user.mapper.SysUserMapper;
//import com.ptu.spzx.user.service.UserInfoService;
//import com.ptu.utils.AuthContextUtil;
//import org.apache.catalina.User;
//import org.apache.xmlbeans.impl.xb.xsdschema.Attribute;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Service;
//import org.springframework.util.DigestUtils;
//
//import java.util.*;
//import java.util.concurrent.TimeUnit;
//
//@Service
//public class UserInfoServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements UserInfoService {
//    @Autowired
//    private SysUserMapper userMapper;
//
//    @Autowired
//    private RedisTemplate<String,String> redisTemplate;
//
//    @Autowired
//    private SysDeptMapper sysDeptMapper;
//
//    @Override
//    public void register(UserRegisterDto userRegisterDto) {
//        //1  userRegisterDto获取数据
//        String username = userRegisterDto.getUsername();
//        String password = userRegisterDto.getPassword();
//        String nickName = userRegisterDto.getNickName();
//        String code = userRegisterDto.getCode();
//        //2 验证码校验
//        //2.1 从redis获取发送验证码
//        String redisCode = redisTemplate.opsForValue().get(username);;
//        //2.2 获取输入的验证码，进行比对
//        if(!redisCode.equals(code)){
//            throw new ptuException(ResultCodeEnum.VALIDATECODE_ERROR);
//        }
//        //3 校验用户名不能重复
//        SysUser user = userMapper.selectByUsername(username);
//        if(user!=null){ //存在相同的用户名
//            throw new ptuException(ResultCodeEnum.USER_NAME_IS_EXISTS);
//        }
//        //4 封装需要添加的数据，调用方法添加数据库 预防空指针异常
//        user = new SysUser();
//        user.setUserName(username);
//        user.setName(nickName);
//        user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
//        user.setPhone(username);
//        user.setStatus(1);
//        user.setSex(0);
//        user.setAvatar("http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoj0hHXhgJNOTSOFsS4uZs8x1ConecaVOB8eIl115xmJZcT4oCicvia7wMEufibKtTLqiaJeanU2Lpg3w/132");
//        ;
//        //5 删除发送验证码
//        redisTemplate.delete(username);
//        userMapper.insert(user);
//    }
//    @Override
//    public void setClassId(List<String> stuIds,String className) {
//        for(String stu:stuIds){
//            userMapper.setClassId(stu,className);
//        }
//    }
//
//    @Override
//    public SysUser getStu(String stuId) {
//        if(stuId==null){
//            throw new ptuException(ResultCodeEnum.STU_LESS);
//        }
//        SysUser userInfo=userMapper.getStu(stuId);
//        return userInfo;
//    }
//
//    @Override
//    public List<SysUser> getStuList(String className) {
//        if(className==null){
//            throw new ptuException(ResultCodeEnum.CLASS_LESS);
//        }
//        List<SysUser> userInfos=userMapper.getStus(className);
//        if(userInfos==null){
//            throw new ptuException(ResultCodeEnum.DATA_ERROR);
//        }
//        return userInfos;
//    }
//
////    @Override
////    public void doAssignDept(AssginStuDeptDto assginStuDeptDto) {
////        String stuId = assginStuDeptDto.getStuId();
////        Long deptId = assginStuDeptDto.getDeptId();
////        List<SysDept> sysDepts = sysDeptMapper.selectAll();
////        String speciality=null;
////        Long parentId;
////        String department=null;
////        for(SysDept sysDept : sysDepts){
////            if(deptId == sysDept.getId()){
////                speciality = sysDept.getDeptName();
////                parentId=sysDept.getParentId();
////                department = sysDeptMapper.selectParentName(parentId);
////            }
////        }
////        Map<String, Object> params = new HashMap<>();
////        try {
////            params.put("department", department);
////            params.put("speciality", speciality);
////            params.put("stuId", stuId);
////        } catch (Exception e) {
////            throw new ptuException(ResultCodeEnum.DATA_ERROR);
////        }
////        userMapper.doAssign(params);
////    }
//
//    @Override
//    public List<String> getStuListByClass(String className) {
//        List<String> stuListByClass = userMapper.getStuListByClass(className);
//        return stuListByClass;
//    }
//
//    @Override
//    public void setClaaNull(String className) {
//        userMapper.setClaaNull(className);
//    }
//
//    @Override
//    public PageInfo<SysUser> getStuListByClassName(List<String> classNames,Integer pageNum,Integer pageSize) {
//        LambdaQueryWrapper<SysUser> lambdaQueryWrapper=new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.in(SysUser::getClassName,classNames);
//        PageHelper.startPage(pageNum,pageSize);
//        List<SysUser> userInfos = userMapper.selectList(lambdaQueryWrapper);
//        PageInfo<SysUser> userInfoPageInfo=new PageInfo<>(userInfos);
//        return userInfoPageInfo;
//    }
//
//    @Override
//    public List<SysUser> getStuListByAllClassName(List<String> stuIds) {
//        List<SysUser> userInfoList=new ArrayList<>();
//        for(String stuId:stuIds){
//            List<SysUser> userInfos = userMapper.getStuListByStuId(stuId);
//            userInfoList.addAll(userInfos);
//        }
//        return userInfoList;
//    }
//
//    @Override
//    public SysUser getStuInfo(String userName) {
//        SysUser userInfo = userMapper.selectByUsername(userName);
//        return userInfo;
//    }
//}
